package com.syuchen.protocol.http;

import java.util.Map;

/**
 * 模拟http请求报文
 */
public class Request {

    /**
     * 请求方法
     */
    private String method;
    /**
     * 请求的uri
     */
    private String uri;
    /**
     * http版本
     */
    private String version;
    /**
     * 请求头
     */
    private Map<String, String> headers;
    /**
     * 请求体
     */
    private String body;


    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }


    /**
     * 常见http请求方法
     * GET/POST/PUT/DELETE/OPTION...
     */
    public final static String GET = "GET";
    public final static String POST = "POST";

    /**
     * 常见请求头字段名称
     */
    public final static String Content_Type = "Content-Type"; //请求体的数据类型
    public final static String Content_Length = "Content-Length"; //请求体的数据长度

    /**
     * 常见请求体类型
     */
    public final static String Json_Content_Type = "application/json"; //json类型

    public String getContentType() {
        return this.getHeaders().get(Content_Type).split(";")[0];
    }

    public String getContentLength() {
        return this.getHeaders().get(Content_Length);
    }

}
